package com.bobo.model;

import java.awt.*;

/**
 * @Author: bobobo
 * @Date: 2019/9/3 11:06
 * @Version：1.0
 */
public class Circle {
    public int x,y;
    private int r;
    public int vx,vy;
    public boolean isFilled = false;

    public Circle(int x, int y, int r, int vx, int vy) {
        this.x = x;
        this.y = y;
        this.r = r;
        this.vx = vx;
        this.vy = vy;
    }

    public int getR(){
        return r;
    }

    public void move(int maxx,int minx,int maxy,int miny){
        x += vx;
        y += vy;
        checkCollision(maxx,minx,maxy,miny);
    }

    //撞击事件
    private void checkCollision(int maxx,int minx,int maxy,int miny){
        if (x - r < minx){
            x = r;
            vx = -vx;
        }
        if (x + r > maxx){
            x = maxx - r;
            vx = -vx;
        }
        if (y - r < miny){
            y = r;
            vy = -vy;
        }
        if (y + r > maxy){
            y = maxy - r;
            vy = -vy;
        }
    }

    public boolean contain(Point p){
        return (x - p.x)*(x - p.x) + (y - p.y)*(y - p.y) <= r*r;
    }
}
